//
//  MerchandiseCell.m
//  ios-supplier
//
//  Created by feynmanyuan on 15/4/20.
//  Copyright (c) 2015年 feynmanyuan. All rights reserved.
//

#import "MerchandiseCell.h"

@interface MerchandiseCell()
@property (weak, nonatomic) IBOutlet UIImageView *cellImageView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UIButton *udSwitch;
@property (weak, nonatomic) IBOutlet UILabel *inventory;//库存
@property (weak, nonatomic) IBOutlet UILabel *countLabel;//重量/数量
- (IBAction)upDownSWClick:(id)sender;

@end

@implementation MerchandiseCell

- (void)awakeFromNib {
    // Initialization code
    [self.udSwitch setImage:[UIImage imageNamed:@"on"] forState:UIControlStateNormal];
    [self.udSwitch setImage:[UIImage imageNamed:@"off"] forState:UIControlStateSelected];
}

-(void)setMerchandise:(JFBMerchandiseDS *)merchandise{
    _merchandise = merchandise;
//    [self.imageView setImage:[UIImage imageNamed:merchandise.imageURL]];
    [self.cellImageView sd_setImageWithURL:[NSURL URLWithString: merchandise.mpURL] placeholderImage:[UIImage imageNamed:ImageDefaultPlaceholder]];
    self.cellImageView.frame = CGRectMake(10, 10, 50, 50);
    self.nameLabel.text = merchandise.name;
    self.countLabel.text = [NSString stringWithFormat:@"%@",merchandise.standard];
    self.priceLabel.text = [NSString stringWithFormat:@"¥ %@", [NSString decimalToString:merchandise.storePrice]];
    self.inventory.text = [NSString stringWithFormat:@"库存 %ld",merchandise.stockNum];
    [self.udSwitch setSelected:merchandise.mpStatus];
    
    if (merchandise.mpStatus == 4) {
        self.udSwitch.selected = YES;
    }else {
        self.udSwitch.selected = NO;
    }
//    if (self.merchandise.category1_id != 25 && self.merchandise.category1_id == 23) // 非移动商户不能修改上下架
//    {
//        self.udSwitch.userInteractionEnabled = NO;
//    }
}
- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    self.cellImageView.bounds =CGRectMake(10,10, 50, 50);
    
    self.cellImageView.frame =CGRectMake(10, 10, 50, 50);
    
    self.cellImageView.contentMode =UIViewContentModeScaleAspectFit;
}

- (IBAction)upDownSWClick:(id)sender {
    if (_clickUpDown) {
        _clickUpDown(self,self.merchandise);
    }
}
- (void) changeModeStatus{
    self.udSwitch.selected = !self.udSwitch.isSelected;
}
@end
